package config

import (
	"baby-fried-rice/internal/pkg/kit/models"
	"errors"
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

var (
	config models.Conf
)

func GetConfig() models.Conf {
	return config
}

func readConfig() error {
	data, err := ioutil.ReadFile("res/config_dev.yaml")
	if err != nil {
		err = errors.New(fmt.Sprintf("failed read config file: %s \n", err))
		return err
	}
	if err = yaml.Unmarshal(data, &config); err != nil {
		err = errors.New(fmt.Sprintf("failed unmarshal config file: %s \n", err))
		return err
	}
	return nil
}

func init() {
	if err := readConfig(); err != nil {
		panic(err)
	}
}
